package com.kamistoat.meimeimall.meimeimallmember.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.kamistoat.meimeimall.common.annotation.DubboAndHTTPExceptionCatch;
import com.kamistoat.meimeimall.common.annotation.LoginRequired;
import com.kamistoat.meimeimall.meimeimallmember.service.MemberLoginLogService;
import com.kamistoat.meimeimall.meimeimallmember.service.MemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.kamistoat.meimeimall.meimeimallmember.entity.MemberEntity;
import com.kamistoat.meimeimall.common.utils.R;


/**
 * 用户Controller
 */
@Api(tags="用户数据库操作")
@RestController
@RequestMapping("member")
public class MemberController {
    @Autowired
    private MemberService memberService;
    @Autowired
    private MemberLoginLogService memberLoginLogService;

    /**
     * 列表
     */
    @ApiOperation("从数据库获取列表")
    @GetMapping("/list")
    @LoginRequired
    @DubboAndHTTPExceptionCatch
    //@RequiresPermissions("meimeimallmember:member:list")
    public R list(@RequestParam Map<String, Object> params) {
        return R.ok();
    }


    /**
     * 信息
     */
    @ApiOperation("从数据库查询指定的POJO")
    @GetMapping("/member_info")
    @LoginRequired
    @DubboAndHTTPExceptionCatch
    //@RequiresPermissions("meimeimallmember:member:info")
    public R info(@RequestParam("id") Long id) {
        MemberEntity member = memberService.getById(id);
        return R.ok().put("member", member);
    }

    /**
     * 保存
     */
    @ApiOperation("向数据库保存POJO")
    @PutMapping("/member_info")
    @LoginRequired
    @DubboAndHTTPExceptionCatch
    //@RequiresPermissions("meimeimallmember:member:save")
    public R save(@RequestBody MemberEntity member) {
        memberService.save(member);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation("向数据库更新POJO")
    @PostMapping("/member_info")
    @LoginRequired
    @DubboAndHTTPExceptionCatch
    //@RequiresPermissions("meimeimallmember:member:update")
    public R update(@RequestBody MemberEntity member) {
        memberService.updateById(member);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("从数据库删除POJO")
    @DeleteMapping("/member_info")
    @LoginRequired
    @DubboAndHTTPExceptionCatch
    //@RequiresPermissions("meimeimallmember:member:delete")
    public R delete(@RequestBody Long[] ids) {
        memberService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
